package org.qloudgen.txn.dilithium.cluster.sqlmap;

import java.io.IOException; 
import java.io.Reader;   

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.io.Resources; 

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory; 
import org.apache.ibatis.session.SqlSessionFactoryBuilder;   

public class MyBatisUtil  {     
	
	static Log log = LogFactory.getLog(MyBatisUtil.class);
	private  final static SqlSessionFactory sqlSessionFactory;     
	
	static {
		String resource = "mybatis-config.xml";       
		Reader reader = null;        
		try {            
			reader = Resources.getResourceAsReader(resource);        
			} 
		catch (IOException e) {            
			log.error(e.getMessage());                   
			}        
		sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);    
		}         
	
	public static SqlSessionFactory getSqlSessionFactory() {        
		return sqlSessionFactory;     
	} 
	
	public static SqlSession getSqlSession(boolean autoCommit){
		return sqlSessionFactory.openSession(autoCommit);
	}
	
} 
